<template>
  <div class="app-container">
    <el-row type="flex">
      <el-form ref="searchform" inline :model="searchform">
        <!-- <el-form-item label="标题">
          <el-input v-model="searchform.bt"></el-input>
        </el-form-item> -->
        <el-form-item label="热点分类">
          <el-select v-model="searchform.taskId" placeholder="请选择热点分类" style="width:250px">
            <el-option label="全部" value=""></el-option>
            <el-option :label="item.keyword" :value="item.taskId" v-for="(item,index) in yqgjclist" :key="index"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="时间" prop="time">
          <el-date-picker
            v-model="time"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd"
            clearable
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="small" @click="search"
            >查询</el-button
          >
          <el-button plain size="small" @click="resetForm('searchform')"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </el-row>

    <el-table
      v-loading="listLoading"
      :data="
        tableData.slice(
          (searchform.pageNum - 1) * searchform.pageSize,
          searchform.pageNum * searchform.pageSize
        )
      "
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column label="序号" type="index" align="center" width="60" />
      <el-table-column label="舆情情感" align="center" width="90">
        <template slot-scope="{ row }">
          <div v-if="row.sentiment">
            <el-tag effect="dark" type="success" v-if="row.sentiment == 'POSITIVE'">正面</el-tag>
            <el-tag effect="dark" v-if="row.sentiment == 'NEUTRAL'">中立</el-tag>
            <el-tag effect="dark" type="warning" v-if="row.sentiment == 'NEGATIVE'">负面</el-tag>
          </div>
          <div v-else>
            <el-tag effect="dark" type="info">暂无</el-tag>
          </div>
        </template
      ></el-table-column>
      <el-table-column
        label="标题"
        align="center"
        prop="djUserName"
        width="250"
      >
        <template slot-scope="{ row }">
          <div class="haha" v-html="row.title"></div> </template
      ></el-table-column>
      <el-table-column label="关键词" prop="requiredKeywords" align="center" width="90">
      </el-table-column>
      <el-table-column label="舆情摘要" align="center" prop="summary">
        <template slot-scope="{ row }">
          <div class="haha" v-html="row.summary"></div>
        </template>
      </el-table-column>
      <el-table-column label="作者" align="center" prop="author" width="110" />
      <el-table-column label="来源" align="center" prop="website" width="110" />
      <el-table-column
        label="发生位置"
        align="center"
        prop="eventPlace"
        width="110"
      />
      <el-table-column
        label="舆情发布时间"
        align="center"
        prop="createDate"
        width="110"
      />
      <el-table-column
        label="创建时间"
        align="center"
        prop="updateDate"
        width="110"
      />
      <el-table-column label="操作" align="center" width="120">
        <template slot-scope="row">
          <el-button size="mini" type="primary" plain @click="view(row)">
            查看详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <div style="padding: 10px" />
    <el-pagination
      layout="total, sizes, prev, pager, next, jumper"
      :page-sizes="[10, 20, 50, 100]"
      :current-page="searchform.pageNum"
      :page-size="searchform.pageSize"
      :total="total"
      @size-change="onPageSizeChange"
      @current-change="onCurrentPageChange"
    />

    <el-dialog
      width="1000px"
      :title="title"
      :visible.sync="show"
      :close-on-click-modal="false"
      :show-close="false"
    >
      <div>的玩法威风威风</div>
      <div slot="footer" style="text-align: center">
        <el-button @click="show = false">关 闭</el-button>
        <el-button v-if="title === '答复'" type="primary" @click="submit">
          提 交
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  getPublicOpinionDetailStatisticsList,
  getPublicOpinionStatisticsList,
} from "@/api2/shishiredian";
import { Collapse } from "element-ui";

export default {
  data() {
    return {
      tableData: [],
      listLoading: true,
      total: 0,
      show: false,
      title: "",
      dialogForm: {},
      yqgjclist: [],
      searchform: {
        pageNum: 1,
        pageSize: 10,
        endTime: "",
        beginTime: "",
        taskId: "",
      },
      time: [],
    };
  },
  filters: {},
  created() {
    this.getPublicOpinionStatisticsList();
    this.getList();
  },
  methods: {
    getPublicOpinionStatisticsList() {
      getPublicOpinionStatisticsList().then((res) => {
        // console.log("haha", res);
        let leibieArr = JSON.parse(res.data).data;
        leibieArr.map((item) => {
          if (item.keyword) {
            this.yqgjclist.push(item);
          }
        });
        // console.log("yqgjclist", this.yqgjclist);
      });
    },
    getList() {
      this.listLoading = true;
      getPublicOpinionDetailStatisticsList(this.searchform).then((res) => {
        this.listLoading = false;
        // console.log(111, res.data, this.searchform);
        let origindata = JSON.parse(res.data);
        this.tableData = origindata.data;
        console.log(1111, this.tableData);
        this.total = origindata.data.length;
      });
    },
    onPageSizeChange(val) {
      this.searchform.pageSize = val;
      this.searchform.pageNum = 1;
      this.getList();
    },
    onCurrentPageChange(val) {
      this.searchform.pageNum = val;
      this.getList();
    },
    search() {
      this.tableData = [];
      this.searchform.pageNum = 1;
      if (this.time) {
        this.searchform.beginTime = this.time[0];
        this.searchform.endTime = this.time[1];
      } else {
        this.searchform.beginTime = "";
        this.searchform.endTime = "";
      }
      console.log(this.searchform, "this.searchform");
      this.getList();
    },
    resetForm(formName) {
      this.time = [];
      this.searchform.pageNum = 1;
      this.searchform.startDate = "";
      this.searchform.endTime = "";
      this.getList();
    },
    async view(e) {
      // this.title = "实时热点详情";
      // this.show = true;
      console.log(e.row, 11);
      // /tongzhi/tongzhi
      window.sessionStorage.setItem(
        "shishiredian_detail",
        JSON.stringify(e.row)
      );
      this.$router.push("/tongzhi/shishiredianDetail");
      // const res = await getLetterInfo({ djLetterId });
      // this.dialogForm = res.data;
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-dialog__body {
  padding-bottom: 0;
}
.haha {
  // border: 1px solid red;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
</style>
